﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraAdjust : MonoBehaviour
{
    private float lastHeight = 0; //上一次实际高度
    private float lastWidth = 0; //上一次实际宽度
    private float size; //开发模式下的摄像机orthographicSize
    private float w = 1920f;
    private float h = 1080f;
   
    private void Awake()
    {
        size = Camera.main.orthographicSize;
        InvokeRepeating("Init", 0, 1f / 5);
    }

    public void Init()
    {
        if (Screen.height != lastHeight || Screen.width != lastWidth)
        {
            //1024/768 是编辑模式下固定的屏幕宽度和屏幕高度,Screen.Height和Screen.Width是实际屏幕高度和实际屏幕宽度
            Camera.main.orthographicSize = size * (w / h) * ((float) Screen.height / Screen.width);
        }

        lastWidth = Screen.width;
        lastHeight = Screen.height;
    }

    //总结就是：摄像机Size = 摄像机原来Size * 原来宽高比 * 实际高宽比
}